package com.dm0858.bianmin.mine.adapter;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.View;

import com.bumptech.glide.Glide;
import com.dm0858.bianmin.R;
import com.dm0858.bianmin.mine.activity.EditPostActivity;
import com.dm0858.bianmin.mine.activity.ReleaseActivity;
import com.dm0858.bianmin.mine.base.BaseRecyclerViewAdapter;
import com.dm0858.bianmin.mine.base.BaseViewHolder;
import com.dm0858.bianmin.mine.bean.PostManagerBeanData;
import com.dm0858.bianmin.mine.model.MineModel;
import com.dm0858.bianmin.mine.network.Retrofit;
import com.dm0858.bianmin.mine.network.RetrofitListener;
import com.dm0858.bianmin.mine.tools.DialogUtils;
import com.dm0858.bianmin.mine.tools.ToastUtils;

import java.util.List;

public class PostManageRecyclerViewAdapter extends BaseRecyclerViewAdapter {

    private Context mContext;

    private List<PostManagerBeanData.DataBean> list;


    /**
     * 构造方法
     *
     * @param mContext
     * @param resource
     * @param data
     */
    public PostManageRecyclerViewAdapter(Context mContext, int resource, List data) {
        super(mContext, resource, data);
        this.mContext = mContext;
        if (data != null) this.list = data;
    }

    @Override
    protected void bindData(BaseViewHolder holder, int position) {
        PostManagerBeanData.DataBean data = list.get(position);
        Glide.with(mContext).load(data.getImage()).into(holder.getImageView(R.id.img_picture));
        holder
                .setText(R.id.txt_title,data.getTitle())
                .setText(R.id.txt_area,data.getArea())
                .setText(R.id.txt_type,data.getSectionName())
                .setText(R.id.txt_date,data.getCreateDate())
                .setOnClickListener(R.id.item, view -> {
                    int typeInt = 0;
                    if (data.getSectionName().equals("租房买房"))
                        typeInt = 10;
                    else if (data.getSectionName().equals("二手汽车"))
                        typeInt = 17;
                    else typeInt = 0;
                    Intent intent = new Intent(mContext, ReleaseActivity.class);
                    intent.putExtra("typeInt",typeInt);
                    intent.putExtra("id",data.getId());
                    mContext.startActivity(intent);
                })
                .setOnLongClickListener(R.id.item, view -> {
                    onLongClickListener.onLongClick(position);
                    return true;
                });
    }

    @Override
    protected int getSize() {
        if (list == null) return 0;
        else return list.size();
    }

    public void setList(List<PostManagerBeanData.DataBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public void setOnLongClickListener(onLongClickListener onLongClickListener) {
        this.onLongClickListener = onLongClickListener;
    }

    private onLongClickListener onLongClickListener;


    public interface onLongClickListener{
        void onLongClick(int position);

    }
}
